/**
 * @version 3 11 February 2013
 * @author Myhaylo Kotsyuruba
 */

public class User {
    private Test userTest;
    private String fullName;
    private AnswerMap[] answerMap;
    
    public User(Test userTest) {
        this.userTest = userTest;
        InputOutputSystem.show("Please, input Your full name:");
        fullName = InputOutputSystem.getText();
    }

    public void getTested() {
        InputOutputSystem.show(userTest.toString());
        int quantityQestions = userTest.getQuantityQuestions();
        answerMap = new AnswerMap[quantityQestions];
        for (int index = 0; index < quantityQestions; index++) {
            InputOutputSystem.show(userTest.toStringQuestion(index));
            answerMap[index] = userTest.convertsUserAnswer(index,
                    InputOutputSystem.getAnswer());
        }
    }
    
    public AnswerMap[] getAnswerMap() {
        return answerMap;
    }

    public void showResault() {
        String result = String.format("%n%nDear %s!%n%n", fullName);
        int maxScore = 0;
        int userScore = 0;
        for (int index =0; index < answerMap.length; index++) {
            result = result.concat(
                    String.format("Qestion %d. You score is %d of %d.%n", 
                    index + 1, answerMap[index].getScore(),
                    userTest.getQuestionScore(index)));
            userScore += answerMap[index].getScore();
            maxScore += userTest.getQuestionScore(index);
        }
        result = result.concat(String.format("%nTOTAL: You score is %d of %d.",
                userScore, maxScore));
        InputOutputSystem.show(result);
    }
}
